package com.zykj.state.stateinfo;

import com.zykj.state.GumballMachine;
import com.zykj.state.State;

/**
 * @author zhoulj(周利军) [1217102780@qq.com]
 * @Module ID:   <(模块)类编号，可以引用系统设计中的类编号>
 * @Comments: <对此类的描述，可以引用系统设计中的描述>
 * @JDK version used:      <JDK1.8> 17
 * @since 2019/1/8-16:17
 */
public class WinnerState implements State {
    GumballMachine gumballMachine;
    public WinnerState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }


    @Override
    public void insertMoney() {
        System.out.println("机器正在处理，请稍后投币");
    }

    @Override
    public void ejectMoney() {
        System.out.println("机器正在处理，无法退币");
    }

    public void turnCrank() {
        System.out.println("机器正在处理，无法操作");
    }

    public void dispense() {
        gumballMachine.releaseBall();
        if(gumballMachine.getCount() == 0){
            gumballMachine.setState(gumballMachine.getSoldOutuarterState());
        }else{
            System.out.println("你获得了奖励");
            gumballMachine.releaseBall();
            if(gumballMachine.getCount() == 0){
                gumballMachine.setState(gumballMachine.getSoldOutuarterState());
            }else{
                gumballMachine.setState(gumballMachine.getNoQuarterState());
            }
        }
    }
}
